home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / CURLPushButton 2.3 / CURLPushButton README < prev    next >
Encoding:
Text File  |  1997-07-21  |  19.6 KB  |  426 lines  |  [TEXT/CWIE]

  1. /*******************************************************************************\
  2. |                                                                                |
  3. | CURLPushButton ©1997 John C. Daub.  All rights reserved                       |
  4. |                                                                                |
  5. | John C. Daub <mailto:hsoi@eden.com>                                            |
  6. | <http://www.eden.com/~hsoi/>  <http://www.eden.com/~hsoi/prog.html>            |
  7. |                                                                                |
  8. \*******************************************************************************/
  9.  
  10.  
  11. DESCRIPTION
  12. ```````````
  13.  
  14. A Metrowerks PowerPlant® inherited class geared towards helping your application
  15. become Internet-savvy.  It allows you to put clickable buttons in places (e.g.
  16. your About box) that will look like a URL in a web browser...click on the URL
  17. and go right to there!  Great for listing the web page for your software,
  18. the email address for contact/support, the ftp site where users can get
  19. updates or whatever you want!  You list the text, they can see it, copy it
  20. down, whatever... and then just click and visit it.  VERY HANDY!! VERY COOL!!
  21.  
  22. The class is even set up that the text of the button can say one thing but
  23. then still visit the URL.  For example, the About Box displays your name
  24. and you click on it and it visits your personal web page or something.  Point
  25. is, the button can list the URL text or not...it's a flexible class.
  26.  
  27. There is a demonstration application included in the archive to help you
  28. see how it works as well as help and tips for implimentation.  Furthermore
  29. there is a CPPb/CTYP file that you can use to aid in the editing process
  30. (for use with Metrowerks Constructor).
  31.  
  32. IMPORTANT:  CURLTextButton gets a lot of its functionality from the wonderful
  33. Internet Configuration System, courtesy of Peter N. Lewis and Quinn! the
  34. Eskimo.  It is not necessary to use Internet Config with CURLTextButton, but
  35. it might simplify things for you if you do use it.  If nothing else, the
  36. demo application uses Internet Config.
  37.  
  38. This means that you can use CURLTextButton alone, but then you'll have to
  39. impliment your own schemes for finding and launching the correct application,
  40. sending the URL to it, etc etc.  So, why reinvent the wheel?  Use IC :)
  41.  
  42. If you wish to use IC to help impliment this, you will need the Internet
  43. Config Programmers Kit.  This is available for free online in many sources.
  44. I'll list the URL to obtain this and other information a little further
  45. down in this file.
  46.  
  47. Also, you might find IC++ from Dan Crevier very helpful here too.  IC++ are
  48. some C++ wrappers that make implimenting IC in your application a lot
  49. easier.  I used IC++ in the demo application, and I'll give you a URL for
  50. the full package again later in this document.
  51.  
  52. MINIMAL PORTIONS OF THE INTERNET CONFIG PROGRAMMERS KIT AND IC++ SHIP
  53. IN THIS ARCHIVE, BUT ONLY SO THE DEMO CAN COMPILE.  IF YOU WISH TO
  54. USE IC AND/OR IC++ YOU SHOULD OBTAIN THE FULL ARCHIVES FOR THESE AS
  55. THEY WILL CONTAIN ALL THE NECESSARY FILES, DOCUMENTATION, SUPPORT/CONTACT
  56. INFORMATION ABOUT/FOR THE AUTHOR(S), ETC.  Again, URL's are below.
  57.  
  58. I'll provide more information about using CURLPushButton in a bit :)
  59.  
  60. Upgraded to work with CodeWarrior Professional 1, CURLPushButton tries to
  61. take advantage of the latest PowerPlant developments, e.g. using CTYP
  62. resources, using the RegisterClass_() macro instead of a static
  63. CreateFromStream method. However, I've done what I can to try to have some
  64. degree of backwards compatability within the source. The demo was built
  65. using CW Pro1.
  66.  
  67.  
  68. WHAT'S NEW WITH 2.0
  69. ```````````````````
  70.  
  71. In version 1.0 (the previous version of the class), it was ok...it behaved
  72. like a push button variation of LTextButton.  It worked and did the job, but
  73. cosmetically I didn't really like it.  The HotSpotAction just called
  74. InvertRect, which was ok to give visual feedback, but wasn't as clean as say
  75. how a link/URL in a web browser would be.  I really wanted the class to
  76. behave in a similar way, InvertRect didn't cut it.
  77.  
  78. So I modified the class to just invert the actual text.  This was accomplished
  79. by drawing the string not in srcOr mode but in srcXor mode.  That worked ok
  80. to give me the behavior that I wanted.  However, the exact inverse color
  81. that one could get could be less than aestheticly pleasing...like blue
  82. inverted to yellow...didn't look that nice.
  83.  
  84. So I decided to allow the ability to specify the RGB color to use when
  85. the button was hilited.  This worked out ok because you could want to have
  86. a blue color when "untouched" and then something like red for when it was
  87. hilited...again similar to the "default" behavior of web browsers.
  88.  
  89. But then I thought that people might want to have more than just a different
  90. color when the button was depressed, like change the style.
  91.  
  92. So here's how it now works:
  93.  
  94. Create a Txtr resource for the "normal" look and feel...usually at least
  95. you'll want srcOr copy mode and centered.  Font, size, style, color are
  96. up to you.
  97.  
  98. Now if you want to use a custom Text Trait for the "depressed" state,
  99. make another along the same lines as the other Txtr, but I'm sure you'll
  100. at least want a different color.
  101.  
  102. Specify the "depressed" Txtr ID in the "Hilited Text Traits" field (in
  103. Constructor).
  104.  
  105. If there is an ID in that field greater than -1 (0 or higher), then
  106. the Txtr will be used.
  107.  
  108. If the value in that field is a negative number, then we fall to the
  109. next chioce...using the specified hilite color.
  110.  
  111. If the "Use Hilite Color" box is checked, then the RGB Value specified
  112. will be used for the hilite color.
  113.  
  114. If it's not checked, then we fall upon the last resort, using the
  115. "main" Txtr and just using a srcXor copy mode.
  116.  
  117. I have tried to demonstrate how this "roll-down-hill" approach works
  118. in the demo application.  Check it out and look at the PPob in
  119. Constructor.  That should help.
  120.  
  121.  
  122. Also what's new in 2.0 are new constructors, a copy and parameterized
  123. constructor.  Most importantly, the parameterized constructor, due to
  124. the many parameters that go into it, has a struct that you'll need to
  125. fill out.  It's similar to SPaneInfo or SViewInfo in concept and purpose.
  126. And since I no longer inherit from LTextButton, hopefully things can
  127. be a bit better in terms of implimentation.
  128.  
  129. Finally, I went from v1.0 straight to 2.0 because well....it was such
  130. a major overhaul. :)
  131.  
  132. DUE TO THIS MAJOR OVERHAUL, I HONESTLY DOUBT THAT THERE IS ENOUGH BACKWARDS
  133. COMPATABILITY WITH VERSION 1.0.  IF YOU ARE CURRENTLY USING v1.0, PLEASE
  134. USE THE 1.0 CTYP/CPPb TO REMOVE YOUR CURLPushButton's FROM YOUR PPob's.
  135. THEN RECONSTRUCT THEM WITH THE NEW VERSION.  I apologize if this causes
  136. any problems, but hopefully with a little time to convert things over,
  137. you'll be able to enjoy and appreciate the new functionality of the
  138. overhauled class.
  139.  
  140.  
  141. HOW TO USE CURLPushButton
  142. `````````````````````````
  143.  
  144. First of course are the "usual" PowerPlant things....
  145.  
  146. There are 2 files: "CURLPushButton 2.0.CTYP" contains the CTYP resource
  147. for Constructor v2.4 and greater, and "CURLPushButton 2.0.CPPb" containing
  148. the CPPb resource for Constructor versions less than 2.4. You can place
  149. these files (or copies of, or aliases to) into the "Custom Types"
  150. folder in your "Metrowerks PowerPlant" folder (if you are working
  151. with something prior to CW Pro1, you can place the file in the same
  152. folder as the Constructor application). This way Constructor, upon launch,
  153. will list CURLPushButton in the Catalog Window (or Display Classes for
  154. Constructor < v2.4), and it will be available to like any other PowerPlant
  155. class (LPane, LButton, etc.)
  156.  
  157. Then you can just drag the CURLPushButton icon from that window into
  158. your PPob resource and go!  Nice ease of editing, just like what Constructor
  159. allows for :-)
  160.  
  161. When you're editing in Constructor, you might want to make a custom
  162. Text Traits resource ('Txtr') for the button.  Since the point of the class
  163. is to show a URL and be similar in look and feel to URLs in web browsers,
  164. I found it nice to create a Txtr that was blue and underlined (and my
  165. choice of Geneva 9 was arbitrary).  I also found it handy to have the
  166. text be aligned to the center, since it will look better when clicked
  167. upon.  You can see in the demo's .ppob file how I did this.  Coloring isn't
  168. a feature inherent to the CURLPushButton class, hence why you need to
  169. do it this way.  It's not vital to have a custom Txtr for the CURLPushButton,
  170. but it makes the button/URL look like that of a web browser and so can
  171. lend some nonverbal cues to the user that if they "click here" something
  172. just might happen. :)
  173.  
  174. Oh, when you make your Text Trait, I'd recommend using a "srcOr"
  175. copy mode, especially if you have a non-white background (like a
  176. grayscale dialog, as in the demo).  This will allow the background
  177. to show through.  Play around...you'll see what I mean.
  178.  
  179. Then in your code you should make sure the CURLPushButton class is
  180. registered (RegisterClass_() macro or URegistrar::RegisterClass()),
  181. and the CURLPushButton.cp file is added to your project file.
  182.  
  183. As then for getting everything to work, it's just a matter of the
  184. PowerPlant broadcaster/listener mechanism.  If you're not familiar
  185. with this mechanism, I highly suggest that you read the chapter
  186. on Controls (which discusses this) in the "PowerPlant Book" by
  187. Jim Trudeau.  This book is in the "CodeWarrior Documentation" folder
  188. on the CodeWarrior Reference CD.
  189.  
  190. You can see in the sample code what I do.  Most important thing is
  191. to have some place/object to ListenToMessage.  In the demo, I
  192. had the CURLTestDialog object ListenToMessage.  When the button's
  193. value message is broadcast, I do check a few things...let me back
  194. up a bit...
  195.  
  196. Notice in the CURLTestDialog constructor I make a CInternetConfig
  197. object?  This is from Dan Crevier's IC++.  If you don't want to
  198. use IC++, you should initialize and start up your IC stuff here
  199. (if not done already elsewhere).  If you get IC started up and working
  200. right (i.e. it's installed on the user's system, no problems
  201. getting it initialized, etc etc etc) then you're good to go.
  202.  
  203. I set a Boolean (mICWorking) based upon the success/failure of
  204. IC starting up.  You might want to do this same thing yourself because
  205. you see...if you GetURL(), that's ok...but then if you try to send
  206. the URL, you're in trouble...IC's not installed or a problem starting
  207. it up, and who knows how your app might fail.
  208.  
  209. If you don't use IC, then hopefully you'll come up with your own
  210. mechanisms to check for this sort of thing.
  211.  
  212. Bottom line of this is that before we GetURL and then send it off
  213. to launch the appropriate helper application, we of course check
  214. for the proper MessageT and then also check to be sure we can
  215. do the URL (e.g. mICWorking == true).  This is a very necessary thing
  216. to do.  With the demo's implimentation, the CURLPushButton will
  217. still click, but then nothing will happen.
  218.  
  219. One nice thing is that the Internet Config system is in the public
  220. domain.  You are welcome to ship the IC application/extension with
  221. your application (or if you want to keep file size small, give a
  222. URL).  This can help users utilize all features of your application,
  223. get them using Internet Config (cause if you're on the net and have
  224. a Mac, there's little reason to not use IC), and life can be good :)
  225.  
  226. I think that about covers how to use CURLPushButton.  Hopefully between
  227. this and the demo application you should be able to get things going.
  228. If not, of course contact me and I'll help you out.  And if these
  229. docs are insufficient, please let me know how to improve upon them.
  230.  
  231. Oh I should say...the implimentation that I use in CURLTestDialog of
  232. course does work...but it's hardly the best ghing...there should
  233. be better error checking, there are a lot of assumptions made, and
  234. that's not good code -- it's just something to suffice for a simple
  235. demo.  Base your own code upon it if you wish, but do try to handle
  236. errors better, contend with odd situations better, etc.
  237.  
  238.  
  239. CREDITS
  240. ```````
  241.  
  242. I wrote this because well...I wanted to have something that would do this :)
  243.  
  244. I should thank Dan Crevier for IC++, Peter N. Lewis and Quinn! for Internet
  245. Config, Ron Davis (friend and co-worker) and James Thomson (author of
  246. the VERY COOL DragThing) for a bit of inspiration, Matt Brunk for the
  247. drag and drop code and suggestion (and the cool SpeedSearch!), and my wife
  248. Michele for putting up with me as I spend all day long at work on a computer
  249. and then come home and spend all night on a computer. :)
  250.  
  251.  
  252. DISCLAIMER
  253. ``````````
  254.  
  255. This is NOT a product of Metrowerks Corporation.  Please do NOT contact Metrowerks
  256. for help/support of this class/code.  If you need support, please use the contact
  257. information given below.
  258.  
  259.  
  260. LICENSING AND USAGE AGREEMENT
  261. `````````````````````````````
  262.  
  263. John C. Daub (author) grants you, and you accept, a nonexclusive, nontransferable
  264. license to distribute this code for you within your programs and projects.  You may
  265. distribute this code in object code form only and only on magnetic diskettes,
  266. CD-ROM, or other media with your programs into which this code has been
  267. incorporated (if you need to distribute your program by some other medium, please
  268. contact the author).  You agree that this license gives you no title nor rights
  269. of ownership in, of, and/or to this code, and acknowledge that this code
  270. is property of John C. Daub.  This code is NOT in the public domain.
  271.  
  272. Permission is granted to the following organizations to distribute this
  273. code on their CD-ROM collections:
  274.  
  275. Pacific HiTech, Inc            - Info-Mac CD-ROM
  276. Celestin Company            - Apprentice CD
  277. Meterowerks Corporation        - CodeWarrior
  278. Bowers Development            - AppMaker
  279.  
  280. If you and/or your organization wishes to distribute this code and are
  281. not explicitly listed above, please contact John C. Daub.
  282.  
  283. You may modify the source code, compile it, and incorporate the resulting object
  284. code into your programs.  If you modify the code, you cannot redistribute the
  285. modified code under the same class/code name.  Furthermore, to prevent any
  286. problems and/or infringements, please contact the author prior to redistribution
  287. of any modified code.
  288.  
  289. John C. Daub licenses this code to you on an "AS IS" basis.  John C. Daub makes
  290. no warranties, neither expressed nor implied, regarding this code, its
  291. merchantability, nor its fitness for any purpose.  John C. Daub agrees to make a
  292. reasonable effort to provide written or verbal corrections for any problems
  293. that might be found in this code.
  294.  
  295. Use of this code must be credited in an appropriate manner and location (such
  296. as printed or online documentation and/or About boxes) with the following
  297. credit line:
  298.  
  299.      CURLPushButton ©1997 John C. Daub.  All rights reserved.
  300.  
  301. If this license is too restrictive with the current law in your state or country,
  302. you should not use this code at all.  Furthermore, if you personally find this
  303. agreement too restrictive or not to your satisfaction, you should not use this
  304. code at all.
  305.  
  306.  
  307. FUTURE
  308. ``````
  309.  
  310. -    Overall, I'm much happier with v2.0 than v1.0.  Looks better, behaves better,
  311.     no LTextButton baggage.  But the one bummer is that because I inherit from
  312.     LControl, editing the PPob in Constructor isn't that WYSIWYG...you can't
  313.     display the title, which is a bummer.  I work around it by creating an
  314.     LCaption into which I put the same title as the CURLPushButton...and then
  315.     I can size up the LCaption and make the CURLPushButton's rect match up.  It
  316.     helps to get around...but...
  317.     
  318.     Maybe depending where Constructor goes in terms of custom resources, I might
  319.     not need to do anything...I like the overall structure where it is, and
  320.     if Constructor will eventually have ways to make the editing better, then I'll
  321.     wait.
  322.  
  323. -    Add more functionality, if needed.  The 2.0 version just had the functionality
  324.     that I personally needed, so if there are other things that you might want
  325.     to see, please let me know.  I'm very open to suggestions and all feedback
  326.     (good or bad).
  327.     
  328.  
  329. CONTACT INFORMATION
  330. ```````````````````
  331.  
  332. Even though you don't need to send me email or register or anything to
  333. use the code, it would still be nice to drop me a line and let me know
  334. what you think.  If you find any bugs or add any cool features, send them
  335. to me so I can add it to the official distribution. Furthermore, if I
  336. have your contact information, I can notify you when new versions are
  337. released -- can be very handy if say there is a fatal crashing bug
  338. in the code or some such. So, it's probably in your own best interest
  339. to drop me a line :-)
  340.  
  341. Also, be sure to visit my web site
  342.  
  343. <http://www.eden.com/~hsoi/prog.html>
  344.  
  345. and "register". I won't know if you're "registered" or not, but it's a nice
  346. way that you can be notified of product updates (e.g. I make a new
  347. version, post it on that page, if you're registered, you'll be emailed
  348. automatically that the page changed).
  349.  
  350. John C. Daub
  351. <mailto:hsoi@eden.com>
  352. <http://www.eden.com/~hsoi/prog.html>
  353.  
  354.  
  355. Internet Config URLs:
  356.  
  357. <http://www.stairways.com/>
  358. <http://www.stairways.com/ic/index.html>
  359. <ftp://ftp.stairways.com//stairways/source/icprogkit1.3.sit.bin>
  360.  
  361. IC++ from Dan Crevier
  362.  
  363. <http://rhino.harvard.edu/dan/Programming.html>
  364. <ftp://rhino.harvard.edu//pub/dan/IC++1.0b2.hqx>
  365.  
  366.  
  367.  
  368. CHANGE HISTORY
  369. ``````````````
  370.  
  371. Date        Vers    Who        Notes
  372. ----------------------------------------------------------------------------
  373. 29 Jan 97    1.0        JCD        - Created and initial release
  374.  
  375. 01 Feb 97    2.0        JCD        - Total rewrite of the class: inherits now from LControl
  376.                             instead of LTextButton (now has copy and parameterized ctors
  377.                             as well as no more of LTextButton's baggage and limits);
  378.                             hilite of the button no longer InvertRect's (still optionally
  379.                             can) but instead can use a second Txtr to specify the hilite,
  380.                             else uses the one Txtr but then a custom hilite color, else
  381.                             just TextMode(srcXOr) to auto-invert; CTYP/CPPb updated to
  382.                             match new capabilites.
  383.  
  384. 19 Feb 97    2.1        JCD        - added preprocessor directives for DebugNew
  385.                             - added functionality so that when the pane is not active
  386.                             the text is drawn dimmed.  Required modifications to DrawSelf,
  387.                             as well as adding ActivateSelf and DeactivateSelf.
  388.  
  389. 22 Jun 97    2.2        JCD        - Updated the licensing agreement.
  390.                             - Cleaned up the sources for readability
  391.                             - Can now compile without any precompiled headers.
  392.                             - Upgraded to CW Pro1
  393.                             - Expanded SURLpbInfo typedef.
  394.                             - Created assignment operator.
  395.                             - Made DrawSelf protected, as it should be.
  396.  
  397. 21 July 97    2.3        JCD        - All ctor's use initialization lists instead of
  398.                             assignment (where possible).
  399.                             - All member data is now private (was protected). Appropriate
  400.                             accessor functions have been created (as public or
  401.                             protected, depending on context). Helps to further abstract
  402.                             the user away from the data (good C++ style).
  403.                             - Added include for PowerPlant_PCH to be consistant with
  404.                             PowerPlant sources.
  405.                             - Inline functions no longer defined within class declaration.
  406.                             Definitions moved outside of the class, but still in the header
  407.                             file. #pragma mark's added to source file to ease navigation
  408.                             and user indexing.
  409.                             - GetInvertRect and SetInvertRect made inline (to be consistant
  410.                             with the above changes). GetInvertRect made const and Set takes
  411.                             a const parameter now. These names made obsolete (tho kept for
  412.                             backwards compatability. All new code should use GetUseInvertRect
  413.                             and SetUseInvertRect instead.
  414.                             - Updated demo so clicking on the OK button in the dialog just
  415.                             quits the application.
  416.                             - Added code to support drag and drop of the control/url so
  417.                             people could more easily get the text for other purposes. Code
  418.                             courtesy of Matt Brunk. (thanx!). This code is optional on two
  419.                             levels: 1. compiler via the _CURLPushButton_DO_DND_ preprocessor
  420.                             directive (for those that desire no drag and drop support at all)
  421.                             2. via DoDragAndDrop(), a runtime method to let you set if a URL
  422.                             button supports this or not (so you can be selective). I didn't
  423.                             want to change the PPob format, so I opted for this technique.
  424.                             Updated demo to suit.
  425.                             - Updated licensing agreement to include Bowers Development and
  426.                             AppMaker, as CURLPushButton will be part of that package.